package leetcode.sword;

public class Solution58_1 {

    public static void main(String[] args) {
        String s = " ";
        s = new Solution58_1().reverseWords(s);
        System.out.println(s);
    }

    public String reverseWords(String s) {
        String[] ss = s.split(" ");
        //翻转
        for(int i=0;i<=(ss.length-1)/2;i++){
            String tmp = ss[i];
            ss[i] = ss[ss.length-1-i];
            ss[ss.length-1-i] = tmp;
        }
        //拼接输出
        String res = "";
        for(int i=0;i<=ss.length-1;i++){
            if(!ss[i].equals("")) res += ss[i]+" ";
        }
        return res.trim();
    }
}
